package com.pwser.common.fallback;

import com.pwser.common.entities.Dept;
import com.pwser.common.interf.DeptServiceInterf;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component //不要忘记添加
public class DeptServiceFallbackFactory implements FallbackFactory<DeptServiceInterf> {
	@Override
	public DeptServiceInterf create(Throwable throwable) {
		return new DeptServiceInterf() {
			@Override
			public Dept get(Long id) {
				return new Dept().setDeptNo(id)
						.setDeptName("该ID：" + id + "没有没有对应的信息,Consumer客户端提供的降级信息,此刻服务Provider已经关闭")
						.setDbSource("no this database in MySQL");
			}

			@Override
			public List<Dept> list() {
				return null;
			}

			@Override
			public boolean add(Dept dept) {
				return false;
			}

			@Override
			public List<String> discovery() {
				return null;
			}

			@Override
			public List<ServiceInstance> getServiceById(String serviceId) {
				return null;
			}

			@Override
			public List<Dept> avalanche() throws InterruptedException {
			    List<Dept> deptlist = new ArrayList<>();
                deptlist.add(new Dept().setDeptName("服务正忙，请稍后再试..."));
				return deptlist;
			}
		};
	}
}
